﻿@model myMvcBlog.Post
@{
    ViewBag.Title = "Edit";
}
<h2>
    Edit</h2>
<!-- markItUp! toolbar settings -->
<script type="text/javascript" src="@Url.Content("~/Content/markitup/sets/default/set.js")"></script>
<!-- markItUp! skin -->
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/markitup/skins/markitup/style.css")" />
<!--  markItUp! toolbar skin -->
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/markitup/sets/default/style.css")" />
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { @class = "postForm" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Post</legend>
        @Html.HiddenFor(model => model.ID)
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.Name)</div>
            <div class="col2">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.UrlName)
            </div>
            <div class="col2">
                @Html.EditorFor(model => model.UrlName)
                @Html.ValidationMessageFor(model => model.UrlName)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.Excerpt)
            </div>
            <div class="col2">
                @Html.TextAreaFor(model => model.Excerpt)
                @Html.ValidationMessageFor(model => model.Excerpt)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.Content)
            </div>
            <div class="col2">
                @Html.TextAreaFor(model => model.Content, new {@id="content"})
                @Html.ValidationMessageFor(model => model.Content)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.PostedTime)
            </div>
            <div class="col2">
                @Html.EditorFor(model => model.PostedTime)
                @Html.ValidationMessageFor(model => model.PostedTime)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.IsPublished)
            </div>
            <div class="col2">
                @Html.CheckBoxFor(model => model.IsPublished)
                @Html.ValidationMessageFor(model => model.IsPublished)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                @Html.LabelFor(model => model.PublishedTime):
            </div>
            <div class="col2">
                @Html.EditorFor(model => model.PublishedTime)
                @Html.ValidationMessageFor(model => model.PublishedTime)
            </div>
        </div>
        <div class="field">
            <div class="col1">
                Category:
            </div>
            <div class="col2">
                @{
           
           foreach (var post in Model.PostCategories)
           {
                    <span>@post.Categories.ToList()[0].Name</span>
           }
                }
            </div>
        </div>
        <div class="field">
            <div class="col1">
                Select Category:
            </div>
            <div class="col2">
                @{
           IList<SelectListItem> categories = new List<SelectListItem>();
           foreach (var item in myMvcBlog.Category.All())
           {
               categories.Add(new SelectListItem() { Value = item.ID.ToString(), Text = item.Name }); ;
           }
                    @Html.DropDownList("Category", categories);
                }
            </div>
        </div>
        <div class="field">
            <div class="col1">
                Tags:
            </div>
            <div class="col2">
                @foreach (var pt in Model.PostTags)
                {
                    <span>
                        @Html.ActionLink("Delete", "DeletePostTag", "Tag", new { postId = Model.ID, tagId = pt.TagID }, null)
                        @pt.Tags.ToList()[0].Name;</span>
                }
            </div>
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
@using (Html.BeginForm("AddPostTag", "Tag", FormMethod.Post))
{
    @Html.Hidden("postId", Model.ID)
    <p>
        <input type="text" name="addTags" /><input type="submit" value=" add " />
    </p>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<!-- markItUp! -->
<script type="text/javascript" src="@Url.Content("~/Content/markitup/jquery.markitup.js")"></script>
<script type="text/javascript">
    $('#content').markItUp(mySettings);
</script>
